package leetcode.biweekly.week80;

//Solution4Test
public class Solution4 {

	// Solution4Test
	public long countSubarrays(int[] nums, long k) {
		int len = nums.length;
		long sum = nums[0];
		int l = 0, r = 1;
		long ans = 0;
		while (r < len) {
			while (r < len && sum * (r - l) < k) {
				ans += r - l;
				sum += nums[r++];
			}
			while (sum * (r - l) >= k) {
				sum -= nums[l++];
			}
		}
		if (sum * (r - l) < k) {
			ans += r - l;
		}
		return ans;
	}

}
